<template>
    <BasicModal v-bind="$attrs" @register="register" :title="getTitle" @ok="submitAudit">
        <a-form ref="formRef" :model="fdata">
            <a-textarea v-model:value="fdata.Cause" rows="3" cols="16" :required="true" />
        </a-form>
    </BasicModal>
</template>
  
<script lang="ts" setup>
import { BasicModal, useModalInner } from '/@/components/Modal';
import { ref, reactive } from 'vue';
import { auditOrBackHandle } from '../LabSampleHandle.api';
import { useUserStore } from '/@/store/modules/user';
import dayjs from 'dayjs';


const userStore = useUserStore();
const getTitle = ref('');
const fdata = reactive({
    Cause: "",
    oper: "",
});
const formData = reactive({
    returnCause: "",
    returnPerson: "",
    auditMark: "",
    auditCause: "",
    auditPerson: "",
    auditTime: "",
});

//根据点击“不同意”、“同意”按钮显示不同的内容
const [register, { setModalProps }] = useModalInner((data) => {
    setModalProps({
        minHeight: 40
    });
    Object.assign(formData, data.formData);
    fdata.oper = data.str;
    if (fdata.oper == 'yes') {
        fdata.Cause = '同意';
        getTitle.value = '审批意见';
    } else {
        fdata.Cause = '';
        getTitle.value = '退回原因';
    }
});

//填写意见后，点确认按钮调用的方法
async function submitAudit() {
    if (fdata.oper == 'yes') {
        //审批通过调用方法
        formData.auditMark = "审批通过";
        formData.auditCause = fdata.Cause;
        formData.auditPerson = userStore.getUserInfo.username;
        const currentDate = dayjs().format('YYYY-MM-DD HH:mm:ss');
        formData.auditTime =currentDate;        
        formData.returnCause = '';
        formData.returnPerson = '';
       await auditOrBackHandle(formData);
    } else {
        //审批退回调用方法
        formData.auditMark = "审批退回";
        formData.returnCause = fdata.Cause;
        formData.returnPerson = userStore.getUserInfo.username;
        await auditOrBackHandle(formData);
    }

}


</script>
  
<style scoped></style>